#include "stdafx.h"
#include "Airplane.h"


Airplane::Airplane(HDC hDC, COLORREF Color, INT Distance, Scale scale) : 
	Target(hDC, Color, Distance) { InitImage(scale); }


void Airplane::InitImage(Scale scale)
{
	Image = new TargetImage(scale, this->hDC, Ellipse, this->Color);
}


Airplane::Airplane(INT Distance) : Target(Distance) {}


Airplane::~Airplane(void) 
{ 
	if (AllocateImageMemory) delete Image; 
}


BOOL Airplane::TestDraw(HDC hDC, Scale scale)
{
	Item* cur = first;

	HBRUSH hbr = CreateSolidBrush(Color);
	HPEN hpen = CreatePen(PS_SOLID, 1, Color);
	SelectObject(hDC, hbr);
	SelectObject(hDC, hpen);
	
	while (cur)
	{
		if (cur->xCoord > scale.GetVisibleRect().left - (scale.GetDistance() >> 1) && cur->xCoord < scale.GetVisibleRect().right + (scale.GetDistance() >> 1) &&
			cur->yCoord > scale.GetVisibleRect().top - (scale.GetDistance() >> 1) && cur->yCoord < scale.GetVisibleRect().bottom + (scale.GetDistance() >> 1))
			Ellipse(hDC, 
			INT((cur->xCoord - scale.GetVisibleRect().left) * scale.GetIncrease() - ((Image->GetRealTargetSize() * scale.GetIncrease()) >> 1)), 
			INT((cur->yCoord - scale.GetVisibleRect().top) * scale.GetIncrease() - ((Image->GetRealTargetSize() * scale.GetIncrease()) >> 1)), 
			INT((cur->xCoord - scale.GetVisibleRect().left) * scale.GetIncrease() + ((Image->GetRealTargetSize() * scale.GetIncrease()) >> 1) + 1), 
			INT((cur->yCoord - scale.GetVisibleRect().top) * scale.GetIncrease() + ((Image->GetRealTargetSize() * scale.GetIncrease()) >> 1) + 1));
		cur = cur->next;
	}

	DeleteObject(hbr);
	DeleteObject(hpen);

	return TRUE;
}


